package com.freshcity.core
{
	import com.freshcity.ILayer;
	import com.freshcity.component.container.Component;
	import com.freshcity.component.container.Window;
	import com.freshcity.manager.LayerManager;
	import com.greensock.TweenMax;
	
	import fl.events.ListEvent;
	
	import flash.display.DisplayObject;
	import flash.display.DisplayObjectContainer;
	import flash.events.Event;
	import flash.utils.Dictionary;

	public class BaseHomeWin extends Window
	{
		protected var container:DisplayObjectContainer;
		protected var _contains:Dictionary=new Dictionary();

		public function BaseHomeWin(layer:ILayer=null, xpos:Number=0, ypos:Number=0,title:String="新窗口")
		{
			super(layer, xpos, ypos,title);
			this.mouseEnabled = false;
			this.visible = false;
			this.hasCloseButton = true;
			this.setSize(640,420); //140,45
		}

		override protected function addChildren():void
		{
			super.addChildren();
		}

		protected function drawContent(event:ListEvent):void
		{
			var index:int=event.index;
			var content:Component;

			if (_contains[index] == null)
				initContent(index);
			content=_contains[index];
			while (container.numChildren > 0){
				var c:DisplayObject = container.getChildAt(0);
				container.removeChildAt(0);
			}
			container.addChild(content);
			content.show();
		}

		protected function initContent(index:int):void
		{

		}

		protected function render():void
		{
			main.currentScene=this;
			this.visible = true;
			//TweenMax.to(this, 0.3, {autoAlpha: 1});
		}

		override public function hide(event:Event=null):void
		{
			main.currentScene=null;
			this.visible = false;
			//TweenMax.to(this, 0.3, {autoAlpha: 0});
		}

		override public function show(event:Event=null):void
		{
			if (!this.parent)
			{
				this.layer = LayerManager.sceneLayer;
				LayerManager.sceneLayer.addChild(this);
			}
			
			this.x = (stage.stageWidth-this.width)/2;
			this.y = (stage.stageHeight-this.height)/2;
			
			if(main.currentScene){
				main.currentScene.visible = false;
				//TweenMax.to(main.currentScene, 0.3, {autoAlpha: 0, onComplete: render});
			}
				render();
		}
	}
}
